package com.zzty.daoimpl;

import com.zzty.common.DBUtil;
import com.zzty.common.DBUtilPool;
import com.zzty.dao.PageDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class PageDaoImpl implements PageDao {
    public String getContentById(Integer id){
        String content=null;
        try{
            Connection cn=DBUtilPool.getConnection();
            PreparedStatement pst = cn.prepareStatement("select content from selfQuestion where id=?");
            pst.setInt(1,id);
            ResultSet rs =pst.executeQuery();
            while (rs.next()){
                content=rs.getString("content");
            }
            DBUtilPool.releaseConnection(cn);
        }catch (Exception e){
            e.printStackTrace();
        }
        return content==null?null:content;
    }
    @Override
    public String getAnswerById(Integer id){
        String answer=null;
        try{
            Connection cn=DBUtilPool.getConnection();
            PreparedStatement pst = cn.prepareStatement("select answerUrl from selfExamTransaction where selfExamId=?");
            pst.setInt(1,id);
            ResultSet rs =pst.executeQuery();
            while (rs.next()){
                answer=rs.getString("content");
            }
            DBUtilPool.releaseConnection(cn);
        }catch (Exception e){
            e.printStackTrace();
        }
        return answer==null?null:answer;
    }
}
